package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.EduExper;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-29
 * Time: 16:54
 *
 * @version 1.0
 */
public class EduExperMapperProvider {

    public String insertOne() {
        return new SQL() {{
            INSERT_INTO("tbl_education_experience");
            VALUES("user_id", "#{userId}");
            VALUES("begin_time", "#{beginTime}");
            VALUES("end_time", "#{endTime}");
            VALUES("school_name", "#{schoolName}");
            VALUES("perfession_name", "#{perfessionName}");
            VALUES("category", "#{category}");
            VALUES("awards_desc", "#{awardsDesc}");
            VALUES("create_time", "#{createTime}");
        }}.toString();
    }


    public String deleteOneById() {
        return new SQL() {{
            UPDATE("tbl_education_experience");
            SET("is_deleted=1");
            WHERE("id=#{id}");
        }}.toString();
    }


    public String updateOne(EduExper eduExper) {
        return new SQL() {{
            UPDATE("tbl_education_experience");

            if (!EmptyUtil.isEmpty(eduExper.getBeginTime())) {
                SET("begin_time=#{beginTime}");
            }
            if (!EmptyUtil.isEmpty(eduExper.getEndTime())) {
                SET("end_time=#{endTime}");
            }
            if (!EmptyUtil.isEmpty(eduExper.getSchoolName())) {
                SET("school_name=#{schoolName}");
            }
            if (!EmptyUtil.isEmpty(eduExper.getPerfessionName())) {
                SET("perfession_name=#{perfessionName}");
            }
            if (!EmptyUtil.isEmpty(eduExper.getCategory())) {
                SET("category=#{category}");
            }
            if (!EmptyUtil.isEmpty(eduExper.getAwardsDesc())) {
                SET("awards_desc=#{awardsDesc}");
            }
            if (!EmptyUtil.isEmpty(eduExper.getCreateTime())) {
                SET("create_time=#{createTime}");
            }  if (!EmptyUtil.isEmpty(eduExper.getId())) {
                SET("id=#{id}");
            }
            WHERE("id=#{id}");

        }}.toString();


    }

    public String listAll() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_education_experience");
            WHERE("is_deleted=0 AND user_id=#{userId}");

        }}.toString();
    }


}
